package Spring;

/**
 * ioc案例
 */
public class spring1 {
    static class tire{
        public tire(int size) {
            System.out.println("轮胎的尺寸为:" +size);
        }
    }
    static class chassis{
        private tire tire;

        public chassis(spring1.tire tire) {
            this.tire = tire;
        }

        public  void init(){

        }
    }
    static class body{
        private chassis chassis;

        public body(spring1.chassis chassis) {
            this.chassis = chassis;
            chassis.init();
        }

        public void init(){

        }
    }
    static class car{
        private body body;

        public car(spring1.body body) {
            this.body = body;
            body.init();
        }

        public void init(){

            System.out.println("车身组装");
        }
    }
    static class color{
        private car car;

        public color(spring1.car car) {
            car.init();
            this.car = car;
        }

        public void init(car car){

            System.out.println("颜色已经设置");
        }
    }

    public static void main(String[] args) {
        tire tire=new tire(15);
        chassis chassis=new chassis(tire);
        body body=new body(chassis);
        car car=new car(body);
        color color=new color(car);
    }
}
